package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.ProductChannel;
import com.ktgj.customer.service.IProductChannelService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 通用产品 - 来源渠道维护Controller
 * 
 * @author ruoyi
 * @date 2022-06-10
 */
@RestController
@RequestMapping("/channel")
public class ProductChannelController extends BaseController
{
    @Autowired
    private IProductChannelService productChannelService;

    /**
     * 查询通用产品 - 来源渠道维护列表
     */
    @PreAuthorize(hasPermi = "customer:channel:list")
    @GetMapping("/list")
    public TableDataInfo list(ProductChannel productChannel)
    {
        startPage();
        List<ProductChannel> list = productChannelService.selectProductChannelList(productChannel);
        return getDataTable(list);
    }

    /**
     * 导出通用产品 - 来源渠道维护列表
     */
    @PreAuthorize(hasPermi = "customer:channel:export")
    @Log(title = "通用产品 - 来源渠道维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductChannel productChannel) throws IOException
    {
        List<ProductChannel> list = productChannelService.selectProductChannelList(productChannel);
        ExcelUtil<ProductChannel> util = new ExcelUtil<ProductChannel>(ProductChannel.class);
        util.exportExcel(response, list, "通用产品 - 来源渠道维护数据");
    }

    /**
     * 获取通用产品 - 来源渠道维护详细信息
     */
    @PreAuthorize(hasPermi = "customer:channel:query")
    @GetMapping(value = "/{channelId}")
    public AjaxResult getInfo(@PathVariable("channelId") Long channelId)
    {
        return AjaxResult.success(productChannelService.selectProductChannelById(channelId));
    }

    /**
     * 新增通用产品 - 来源渠道维护
     */
    @PreAuthorize(hasPermi = "customer:channel:add")
    @Log(title = "通用产品 - 来源渠道维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductChannel productChannel)
    {
        return toAjax(productChannelService.insertProductChannel(productChannel));
    }

    /**
     * 修改通用产品 - 来源渠道维护
     */
    @PreAuthorize(hasPermi = "customer:channel:edit")
    @Log(title = "通用产品 - 来源渠道维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductChannel productChannel)
    {
        return toAjax(productChannelService.updateProductChannel(productChannel));
    }

    /**
     * 删除通用产品 - 来源渠道维护
     */
    @PreAuthorize(hasPermi = "customer:channel:remove")
    @Log(title = "通用产品 - 来源渠道维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{channelIds}")
    public AjaxResult remove(@PathVariable Long[] channelIds)
    {
        return toAjax(productChannelService.deleteProductChannelByIds(channelIds));
    }

    /**
     * 查询通用产品 - 来源渠道下拉列表
     */
    @GetMapping("queryProductChanneSelect")
    public AjaxResult queryProductChanneSelect() {
        return AjaxResult.success(productChannelService.queryProductChanneSelect());
    }


}
